/**
 * 
 */
package fr.miage.client.presentation.top;

import com.google.gwt.i18n.client.Constants;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.KeyboardListenerAdapter;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.TextBoxBase;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author romain
 *
 */
public class Login {





  /**
   * Initialize this example.
   */
  public Widget onInitialize() {
    // Create a panel to layout the widgets
    VerticalPanel vpanel = new VerticalPanel();
    vpanel.setSpacing(5);

    // Add a normal and disabled text box
    TextBox normalText = new TextBox();
    normalText.ensureDebugId("cwBasicText-textbox");
    PasswordTextBox normalPassword = new PasswordTextBox();
    normalPassword.ensureDebugId("cwBasicText-textbox-disabled");
    normalPassword.setText("test 1");
    normalPassword.setEnabled(true);
    vpanel.add(new HTML("test2"));
    vpanel.add(createTextExample(normalText, true));
    vpanel.add(createTextExample(normalPassword, false));
    return vpanel;
  }

  /**
   * Create a TextBox example that includes the text box and an optional
   * listener that updates a Label with the currently selected text.
   * 
   * @param textBox the text box to listen to
   * @param addSelection add listeners to update label
   * @return the Label that will be updated
   */
  private HorizontalPanel createTextExample(final TextBoxBase textBox,
      boolean addSelection) {
    // Add the text box and label to a panel
    HorizontalPanel hPanel = new HorizontalPanel();
    hPanel.setSpacing(4);
    hPanel.add(textBox);

    // Add listeners
    if (addSelection) {
      // Create the new label
      final Label label = new Label("test 5 - Label" + ": 0, 0");

      // Add a KeyboardListener
      textBox.addKeyboardListener(new KeyboardListenerAdapter() {
        @Override
        public void onKeyUp(Widget sender, char keyCode, int modifiers) {
          updateSelectionLabel(textBox, label);
        }
      });

      // Add a ClickListener
      textBox.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
          updateSelectionLabel(textBox, label);
        }
      });

      // Add the label to the box
      hPanel.add(label);
    }

    // Return the panel
    return hPanel;
  }

  /**
   * Update the text in one of the selection labels.
   * 
   * @param textBox the text box
   * @param label the label to update
   */
  private void updateSelectionLabel(TextBoxBase textBox, Label label) {
    label.setText("test 66" + ": "
        + textBox.getCursorPos() + ", " + textBox.getSelectionLength());
  }
  public Login(){
  	super();
  	
  }
}
